package com.bocaizp.operation.mapper;

import com.bocaizp.pojo.VO.CityFlagVO;
import com.bocaizp.pojo.VO.IndustryDirectionVO;
import com.bocaizp.pojo.entity.Employee;
import com.bocaizp.pojo.entity.User;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Author : huang jie
 * Date : 2024/5/2 18:21
 **/
@Mapper
public interface LoginMapper {

	/**
	 * 用户登录
	 * @param cardId
	 * @return
	 */
	@Select("select * from user where card_id = #{cardId}")
	User login(String cardId);

	/**
	 * 注册账号前，查询账号是否已被注册
	 * @param cardId
	 * @return
	 */
	@Select("select id, username from user where card_id = #{cardId}")
	User query(String cardId);

	/**
	 * 用户注册
	 * @param cardId
	 * @param password
	 */
	@Insert("insert into user (card_id, password) values (#{cardId}, #{password})")
	void insert(@Param("cardId") String cardId,@Param("password") String password);

	/**
	 * 找回密码
	 * @param cardId
	 * @return
	 */
	@Select("select id, username, password, card_id from user where card_id = #{cardId}")
	User queryName(String cardId);

	/**
	 * 获取城市首字母
	 *
	 * @return
	 */
	@Select("select flag from city group by flag")
	List<CityFlagVO> getFlag();

	/**
	 * 获取城市列表
	 * @param flag
	 * @return
	 */
	@Select("select name from city where flag = #{flag}")
	List<String> getName(String flag);

	/**
	 * 获取职位分类
	 * @param industry
	 * @return
	 */
	@Select("select direction from position where father = #{industry} group by direction")
	List<IndustryDirectionVO> getDirection(String industry);

	/**
	 * 获取职位分类下的职位名称
	 * @param direction
	 * @return
	 */
	@Select("select name from position where direction = #{direction}")
	List<String> getJob(String direction);

	/**
	 * 更新用户所有信息
	 * @param user
	 */
	void update(User user);

	/**
	 * 获取用户所有信息
	 * @param id
	 * @return
	 */
	@Select("select * from user where id = #{id}")
	User getInfo(Long id);

	/**
	 * 更新登录时间
	 *
	 * @param localDateTime
	 * @param id
	 */
	@Update("update user set last_login_time = #{localDateTime} where id = #{id}")
	void updateTime(@Param("localDateTime") LocalDateTime localDateTime,@Param("id") Long id);

	/**
	 * 更新登录次数
	 *
	 * @param id
	 * @param i
	 * @param localDateTime
	 */
	@Update("update user set login_number = #{i}, last_login_time = #{localDateTime} where id = #{id}")
	void loginNumber(@Param("id") Long id,@Param("i") int i,@Param("localDateTime") LocalDateTime localDateTime);

	/**
	 * 员工登录，信息查询
	 * @param empId
	 * @return
	 */
	@Select("select * from employee where emp_id = #{empId}")
	Employee getEmployee(String empId);
}
